home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / entrdata.zip / TESTDATA.PAS < prev   
Pascal/Delphi Source File  |  1993-01-04  |  5KB  |  170 lines

  1. program testdata;
  2.  
  3. uses
  4.   crt,
  5.   qwik,     {The regular Qwik utils}
  6.   strs,
  7.   wndw,
  8.   Wutil,
  9.   goof,
  10.   entrdata;   {The Data entry unit}
  11.  
  12. {$F+}
  13. procedure KbdIdle;
  14. begin
  15. end;
  16. {$F-}
  17.  
  18. {$F+}
  19. procedure BadEntry;
  20. { Example of procedure that can get called if they enter bad
  21.   data (ie, "1.2." for a real)}
  22. begin
  23.   MakeWindow(0,0,3,17,White+RedBG,White+RedBG,EvenSolidBrdr,aWindow);
  24.   WWriteC(1,'Invalid entry');
  25.   sound(200);
  26.   delay(200);
  27.   nosound;
  28.   delay(1500);
  29.   RemoveWindow;
  30. end;
  31. {$F-}
  32.  
  33. procedure SetDataEntryDefaults;
  34. {This procedure must be included and called by the program using entrdata.
  35.  The default colors and other entrdata settings are specified here.}
  36. begin
  37.   {First, the default colors for field input, output}
  38.   if QvideoMode=Mono then
  39.     begin
  40.       DataEntryIattr := LightGray; { Input  attribute : when editing field}
  41.       DataEntryOattr := White;     { Output attribute : normal field display}
  42.       {Optional Attribute of Data Entry hilite when using EnterSeq. Hilites
  43.       field when selected before CR is hit to edit. Use SameAttr if not desired}
  44.       DataPad.Hattr  := LightGrayBG;
  45.     end
  46.   else
  47.     begin
  48.       DataEntryIattr := Yellow+MagentaBG;  { Input  attribute }
  49.       DataEntryOattr := Black+LightGrayBG; { Output attribute }
  50.       DataPad.Hattr  := White+CyanBG;
  51.     end;
  52.  
  53.   {The address of a FAR procedure can be assigned here to point to
  54.    error handler procedure if data entry error. (defaults to nil = none)}
  55.  
  56.   DataPad.ErrHandlerProc:=@BadEntry;
  57.  
  58.   {The following typed constants can be changed interactively by program.}
  59.  
  60.   AutoTab := true;    {After sequential entry, tab to next one in sequence }
  61.  
  62.   AutoNumLock:=false; {sets num lock on for numeric data entry}
  63.  
  64.   {DataWriteMode: ScrnRel (default) forces DataIO routines write to screen
  65.    relative Row & Col, and WndwRel causes it to use window relative coords.}
  66.  
  67.   { DataWriteMode:=WndwRel; }
  68.  
  69.   SeqDoneKey := F10Key; {This is the function key to end sequencial data entry}
  70.  
  71. end;
  72.  
  73.  
  74. {Example follows}
  75.  
  76. var
  77.   MyEntries : DEGroupRec;  {Our local group of data entry records}
  78. type
  79.   { Our local data entry names }
  80.   MyEntryNames = (NoDE,aIntegerDE,aRealDE,aStringDE);
  81.                 { ^^^^ First must ALWAYS be a dummy }
  82.  
  83. const {TEST}
  84.   aReal:    real    = 1.234;
  85.   aInteger: integer = 200;
  86.   aString : string[50] = 'This is a nice long string.';
  87.  
  88.  
  89. {$F+}
  90. procedure VerifyAinteger;
  91. const
  92.   OopsMsg = 'OOPS - that''s > 500';
  93. begin
  94.   with DataPad do
  95.     if Idata>500 then
  96.       begin
  97.         QWrite(20,1,SameAttr,OopsMsg);
  98.         delay(2000);
  99.         QFill(20,1,1,length(OopsMsg),SameAttr,' ');
  100.         RangeOK:=false;
  101.       end;
  102. end;
  103. {$F-}
  104.  
  105. {$F+}
  106. procedure TranslateCase;
  107. begin
  108.   if not ExtKey then
  109.     Key:=upcase(Key);
  110. end;
  111. {$F-}
  112.  
  113. procedure SetMyDataEntries;
  114. {User defined procedure to setup all data entries in a group.}
  115. begin
  116.   with TopEntry do
  117.     begin
  118.       GetDataEntry (MyEntries,ord(aIntegerDE)); {Allocate the entry rec}
  119.       VarAddr     := @aInteger;                 {Assign variable address}
  120.       TypeOfData  := Integers;                  {Specify type of data}
  121.       Row         := 5;                  {Row & column for data}
  122.       Col         := 10;                 {DataWriteMode sets Scrn vs Wndw rel}
  123.       Field       := 4;                  {Field will display this many chars}
  124.       CheckRangeProc := @VerifyAinteger; {User defined range check proc}
  125.       SaveDataEntry;
  126.  
  127.       GetDataEntry (MyEntries,ord(aRealDE));
  128.       VarAddr     := @aReal;
  129.       TypeOfData  := Reals;
  130.       SetName     := RealSet;            {set of valid input chars}
  131.       Row         := 6;
  132.       Col         := 10;
  133.       Field       := 7;
  134.       Decimals    := 3;
  135.       SaveDataEntry;
  136.  
  137.       GetDataEntry (MyEntries,ord(aStringDE));
  138.       VarAddr     := @aString;
  139.       TypeOfData  := Strings;
  140.       SetName     := CharSet;
  141.       Row         := 7;
  142.       Col         := 10;
  143.       Field       := 20;
  144.       MaxField    := pred(sizeof(aString)); {will scroll to accept this many}
  145.       TranslateProc := @TranslateCase;      {User defined xlate proc}
  146.       SaveDataEntry;
  147.  
  148.     end;
  149. end;  { procedure SetMyDataEntries }
  150.  
  151.  
  152. var
  153.   StartField : word;
  154.  
  155. BEGIN {Main block}
  156.   InitWindow(LightGray+BlueBG,true); {Not necessary for using entrdata}
  157.   Qwrite(2,10,SameAttr,'Use F10 to exit.');
  158.   AddrKbdIdle:=@KbdIdle;
  159.   SetDataEntryDefaults;
  160.   AllocateDataEntries(MyEntries,ord(aStringDE)); {ord of last = # of entries}
  161.   SetMyDataEntries;
  162.   DisplayFields(MyEntries,ord(aIntegerDE),ord(aStringDE));
  163.   StartField:=ord(aIntegerDE);
  164.   EnterSeq(MyEntries,ord(aIntegerDE),ord(aStringDE),StartField);
  165.   RemoveDataEntries(MyEntries); {Free the space used for local DEs}
  166.   GotoRC(24,1);
  167.   SetCursor(CursorInitial);
  168. END.
  169.  
  170.